#pragma once

#include <string>
#include <vector>
#include <iterator>
#include "ProcessCommDLLMag.h"
using namespace std;

typedef struct tagIPCMessage
{
	bool bUngent;
	int nCmdID;
	wstring strFrom;
	wstring strTo;
	vector<int> vecIntPara;
	vector<wstring> vecStrPara;

	tagIPCMessage()
	{
		nCmdID = 0;
		bUngent = false;
	}

	tagIPCMessage(const tagIPCMessage& message)
	{
		bUngent = message.bUngent;
		nCmdID = message.nCmdID;
		strFrom = message.strFrom;
		strTo = message.strTo;
		vecIntPara.clear();
		vecStrPara.clear();
		copy(message.vecIntPara.begin(), message.vecIntPara.end(), back_inserter(vecIntPara));
		copy(message.vecStrPara.begin(), message.vecStrPara.end(), back_inserter(vecStrPara));
	}

	tagIPCMessage& operator= (const tagIPCMessage& message)
	{
		bUngent = message.bUngent;
		nCmdID = message.nCmdID;
		strFrom = message.strFrom;
		strTo = message.strTo;
		vecIntPara.clear();
		vecStrPara.clear();
		copy(message.vecIntPara.begin(), message.vecIntPara.end(), back_inserter(vecIntPara));
		copy(message.vecStrPara.begin(), message.vecStrPara.end(), back_inserter(vecStrPara));
		return *this;
	}
	void TranslateToProcessMsg(ProcessMsg& msg) const
	{
		wcscpy_s(msg.szFrom, strFrom.c_str());
		wcscpy_s(msg.szTo, strTo.c_str());
		msg.IntValidNum = static_cast<unsigned>(vecIntPara.size());
		msg.strValidNum = static_cast<unsigned>(vecStrPara.size());
		vector<int>::const_iterator it = vecIntPara.begin();
		vector<wstring>::const_iterator itStr = vecStrPara.begin();
		for (int i = 0; (it != vecIntPara.end()) && (i < PRC_MSG_PARAM_NUM); ++it, ++i)
		{
			msg.IntPara[i] = (*it);
		}
		for (int i = 0; (itStr != vecStrPara.end()) && (i < PRC_MSG_PARAM_NUM); ++itStr, ++i)
		{
			wcscpy_s(msg.StrPara[i], itStr->c_str());
		}
		msg.nCmdID = this->nCmdID;
	}

	void TranslateFromProcessMsg(const ProcessMsg& msg)
	{
		strFrom = msg.szFrom;
		strTo = msg.szTo;
		nCmdID = msg.nCmdID;
		for (unsigned i = 0; i < min(msg.IntValidNum, PRC_MSG_PARAM_NUM); i++)
		{
			vecIntPara.push_back(msg.IntPara[i]);
		}
		for (unsigned i = 0; i < min(msg.strValidNum, PRC_MSG_PARAM_NUM); i++)
		{
			vecStrPara.push_back(msg.StrPara[i]);
		}
	}

}IPCMessage;